<?php
/**
 * Created by PhpStorm.
 * User: tyrans@qq.com
 * Date: 2018/8/17
 * Time: 13:21
 */
namespace App\Handlers;

use EasyWeChat\Factory;
use EasyWeChat\Kernel\Contracts\EventHandlerInterface;
use Illuminate\Support\Facades\Log;

class WechatTextHandle implements EventHandlerInterface
{
    public function handle($payload = null)
    {
        // TODO: Implement handle() method.
        $app = Factory::officialAccount(config('wechat.official_account'));
        if ($payload['MsgType'] === 'text') {
            if ($payload['Content'] == 'openid') {
                return $payload['FromUserName'];
            } else {
                $return = robotResponse($payload['Content']);
                $return = json_decode($return, true);
                return $return['results'][0]['values']['text'];
            }
        }
    }
}